using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TradeFlow.Server.Service;
using System.Threading.Tasks;

namespace TradeFlow.Web.Controllers;

/// <summary>
/// 首页控制器
/// </summary>
[Authorize]
public class HomeController : Controller
{
    private readonly JxHomeService _homeService;

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="homeService"></param>
    public HomeController(JxHomeService homeService)
    {
        _homeService = homeService;
    }

    /// <summary>
    /// 首页
    /// </summary>
    /// <returns></returns>
    public IActionResult Index()
    {
        return View();
    }

    /// <summary>
    /// 普通用户页面
    /// </summary>
    /// <returns></returns>
    public IActionResult nomal()
    {
        return View();
    }

    /// <summary>
    /// 菜单页面
    /// </summary>
    /// <returns></returns>
    public IActionResult menu()
    {
        return View();
    }

    /// <summary>
    /// 管理员页面
    /// </summary>
    /// <returns></returns>
    public IActionResult admin()
    {
        return View();
    }

    /// <summary>
    /// 获取首页统计信息
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetHomeInfo()
    {
        var result = await _homeService.GetHomeInfoAsync();
        return Json(result);
    }

    /// <summary>
    /// 获取单据数量统计
    /// </summary>
    /// <param name="startDate">开始日期</param>
    /// <param name="endDate">结束日期</param>
    /// <returns></returns>
    [HttpGet]
    public async Task<IActionResult> GetBillCount(string startDate = null)
    {
        var result = await _homeService.GetBillCountAsync(startDate);
        return Json(result);
    }
}
